home *** CD-ROM | disk | FTP | other *** search
- Path: news.mindspring.com!usenet
- From: rudd@mindspring.com (Justin Rudd)
- Newsgroups: comp.lang.c++
- Subject: Re: C++ Shortcomings ?
- Date: Fri, 15 Mar 1996 04:05:17 GMT
- Organization: MindSpring Enterprises
- Message-ID: <4iaqch$moh@B1FF.mindspring.com>
- References: <31488E8D.167E@aw.sgi.com>
- Reply-To: rudd@mindspring.com
- NNTP-Posting-Host: rudd.mindspring.com
- X-Newsreader: Forte Free Agent v0.55
-
- Emmanuel Mogenet <mgix@aw.sgi.com> wrote:
-
- >In other word, make portions of the interface to a class private to
- >only some classes.
-
- > 1. Wouldn't that be nicer than the friend mechanism that cracks
- > open a class a spill its guts ?
- > 2. Is there a clean way to achieve in today's C++ standard ?
- > 3. Or is it a bad idea altogether ?
-
-
- I'm not sure what you mean by this...You want to have a function
- SomeMethodOnlyCallableByManagerForClassA(); That can be called like
- this:
-
- ManagerForClassA manage;
- manage.SomeMethodOnlyCallableByManagerForClassA();
-
- hm...OH WAIT...I get it....
-
- even though ManagerForClassA has no idea what it has inside it should
- still be able to call a member function of A.
-
- Well this could be simulate using inheritance. Hm...I've never really
- thought about this...let me get back to you on this one.
-
- >2. Pointer type manipulation
- >-----------------------------
-
- >A very disappointing thing in C++ (unless I am mistaken and it is actually
- >possible to do so) is the following situation:
-
- >If A is a class, then most operations on A can be redefined.
- >Because A is a full blown type.
-
- >Sadly, the same can not be said about A* (type: pointer to A).
-
- >Even though A* is a type, none of its default manipulations
- >can be redefined.
-
- >Example: You can tell C++, that you want to gain control of the
- >situation whenever an object of type A is duplicated.
-
- >You do so by redefining the default copy constructor and the default
- >assignment operator.
-
- >But can you tell C++ that you want to gain control whenever a pointer of
- >A* is duplicated ? Why can't I redefine the copy constructor for the type A* ?
-
- >In my way of looking at thing, that'd be a *great* way of doing clean reference
- >counting, instead of half-baked method using a redefinition of operator->.
-
- >Comments ?
-
- Ok...so you are saying you can do something like this...
-
- A a1, a2;
-
- a1 = a2;
-
- But you want to be able to do this
-
- A a1, *a2;
-
- a1 = a2;
-
- Well you can if you deference the pointer like this
-
- a1 = *a2;
-
- But what you are suggesting although it would be nice sometimes is
- really impossible. Because a2 points to a memory address that holds
- an object of type A. You can't expect the compiler or linker to see
- this:
-
- A a1, *a2;
-
- a1 = a2;
-
- and go look at the memory address and determine it is a location that
- holds an object of type A and then do the regular assignment. Like I
- said before it would be nice but shouldn't be done. Because what
- happens if I have this
-
- class Graphics
- {
- public:
- virtual void Draw() = 0;
- };
-
- class Box
- {
- public:
- virtual void Draw();
- };
-
- class Line
- {
- public:
- virtual void Draw();
- };
-
- void main()
- {
- Graphics* graph;
- Box box1, box2;
- Line line1, line2;
-
- graph = &box1;
- graph->Draw();
-
- box2 = graph; //what you want is this to assign box1 to box2
-
- graph = &line1;
- graph->Draw();
-
- box2 = graph; //before this worked but now it won't because it is
- // a line object. If you build this kind of checking into
- // the language you will severly slow it down.
- }
-
- Like I said in the comments you will slow the speed of your program
- down because of this type of checking and since these are virtual
- functions it will be slowed down even more because its not determined
- till runtime.
-
- I know I was probably rambling and I'll get flamed for some of the
- comments but...these are my comments and let it be known I speak my
- mind.
-
- Justin
-
-